<template>
	<!--index.wxml-->

	<view class="container">
		<view class="swiper-box">
			<view class="nickname-box">
				<view class="nickname" v-if="userInfo">
					<image :src="userInfo.headimg" class="headimg"></image>
					<view>
						<view class="">
							{{userInfo.nickname}}
						</view>
						<view class="">
							{{userInfo.phone}}
						</view>
						<!-- <button open-type="getPhoneNumber" class="phone_button" @getphonenumber="getPhoneNum">获取手机号</button> -->
					</view>
				</view>
				<view class="login-wrap" v-else>
					<view class="login-btn" @click="openPopup">
						立即登录
					</view>
				</view>
				
			</view>
			<image src="https://shops.cg500.com/static/aijiu/bg@2x.png" class="backimg"></image>
			<view class="inner">
				<view class="" style="width: 335px;">
					<view class="list" @tap="uselist">
						<view class="left">
							<view class="text-title">订单记录</view>
							<view style="padding:0px 10px;">
								<view class="text-btn">立即查看</view>
							</view>
						</view>
						<view class="right">
							<image src="/static/images/shiyongjilu@2x.png" class></image>
						</view>
					</view>
				</view>
				
				 <!-- @tap="obligation" -->
				<!-- <view class="list" @tap="obligation">
					<view class="left">
						<view class="text-title">等待付款</view>
						<view style="padding:0px 10px;">
							<view class="text-btn">立即查看</view>
						</view>
					</view>
					<view class="right">
						<image src="/static/images/dengdaifukuan@2x.png" class></image>
					</view>
				</view> -->
			</view>
		</view>
		<view class="list-mine">
			<view class="list-cell" @tap="totext(0)" data-cate="产品介绍">
				<image src="/static/images/chanpjs@2x.png"></image>
				<view>产品介绍</view>
				<image style="position:absolute; right:0px;" src="/static/images/right.png"></image>
			</view>
			<view class="list-cell" @tap="totext(1)">
				<image src="/static/images/zhaosjs@2x.png"></image>
				<view>招商加盟介绍</view>
				<image style="position:absolute; right:0px;" src="/static/images/right.png"></image>
			</view>
			<view class="list-cell" @tap="totext(2)" data-cate="公司介绍">
				<image src="/static/images/gsjs@2x.png"></image>
				<view>公司介绍</view>
				<image style="position:absolute; right:0px;" src="/static/images/right.png"></image>
			</view>
			<view v-if="shangjia" class="list-cell" @tap="toEquipment" data-cate="公司介绍">
				<image src="/static/images/gsjs@2x.png"></image>
				<view>设备列表</view>
				<image style="position:absolute; right:0px;" src="/static/images/right.png"></image>
			</view>
		</view>
		
		<!-- 登录弹窗 -->
		<ns-login ref="login" @loginSuccess="loginSuccess"></ns-login>
			<block v-if="is_phone">
				
				<view class="container" style="padding:0rpx;background: #000;opacity: 0.5;" >
				</view>
				<view style=" width: 100%; height: 100px; display: flex;  justify-content: center; position: fixed; top: 45%;">
					
				
				<view style=" width: 55%;height: 100px; " >
					<button style="button:none;" class="phone_button"  lang="zh_CN" open-type='getPhoneNumber'  @getphonenumber="getPhoneNum">获取手机号</button>
					
				</view>
				</view>
			</block>
	</view>
</template>

<script>
	//index.js
	const app = getApp().globalData;
	import nsLogin from "../../components/ns-login/ns-login.vue"
	export default {
		data() {
			return {
				background: ["/static/images/agent_img01599810087.jpeg", "/static/images/idimg01599807828.jpeg",
					"/static/images/idimg11599810002.jpeg"
				],
				indicatorDots: true,
				vertical: false,
				autoplay: false,
				interval: 2000,
				duration: 500,
				// userInfo: "",
				userInfo: {},
				user: "",
				photo: '',
				is_phone:false,
				shangjia: false,//是否商家 true是
				shopId: '',//商家id
			};
		},

		components: {
			nsLogin
		},
		props: {},
		onLoad: function() {
			console.log(uni.getStorageSync('userInfo'), 'userinfo')
			// this.userInfo = uni.getStorageSync('userInfo')
			// app.employCallback = employ => {
			//   console.log(app.userInfo);

			//   if (employ != '') {
			//     this.setData({
			//       userInfo: app.user_info
			//     });
			//   }
			// };

			this.setData({
				user: app.user_info
			});
			console.log(this.user);
		},
		onShow: function() {
			var _this = this;
			_this.userInfo = uni.getStorageSync('userInfo')
			if(_this.userInfo && _this.userInfo.phone == ''){
				_this.is_phone=true
			}
			if(uni.getStorageSync('userId')){
				this.checkShop()
			}
			// _this.photo = uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo').headimg : ''
			// console.log(_this.photo,'_this.photo')
		},
		methods: {
			// 判断是否商家
			checkShop(){
				var _this = this;
				uni.request({
					url: app.post_url + '/aijiu/api.Shop/isShop',
					data: {
						uid: uni.getStorageSync('userId')
					},
					method: 'post',
				
					success(res) {
						if(res.data.code == 1){
							_this.shangjia = true
							_this.shopId = res.data.data.id
						}
					}
				
				});
			},
			//登录按钮
			getPhoneNum(e) {
			  console.log(e)
			  var detail = e.detail
			  var that = this;
			  if (detail.errMsg == "getPhoneNumber:ok") {
			    var code = detail.code
				uni.request({
					url: app.post_url + '/wechat/api.Login/getMobile',
					//仅为示例，并非真实的接口地址
					data: {
						code: code,
						uid:uni.getStorageSync('userId')
					},
					method: 'post',
				
					success(res) {
						
						that.getuserinfo()
					}
				
				});
			  }
			},
			getuserinfo(){
				var that = this;
				uni.request({
					url: app.post_url + '/wechat/api.Login/userInfo',
					//仅为示例，并非真实的接口地址
					data: {
						
						uid:uni.getStorageSync('userId')
					},
					method: 'post',
				
					success(res) {
						uni.setStorageSync('userInfo',res.data.data)
						that.userInfo=res.data.data
						that.is_phone=false
					}
				
				});
				
			},
			loginSuccess(){
				this.userInfo = uni.getStorageSync('userInfo')
				this.user_id = uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo').id : ''
				
				this.login_check = uni.getStorageSync('login_check')
				// this.getorder(this.user_id);
				// this.photo = uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo').photo : ''
				this.userInfo = uni.getStorageSync('userInfo')
				if(this.userInfo && this.userInfo.phone == ''){
					this.is_phone=true
				}
				if(uni.getStorageSync('userId')){
					this.checkShop()
				}
				
			},
			openPopup() {
				// #ifdef MP-WEIXIN
				this.$refs.login.open()
				// #endif
				// #ifdef MP-ALIPAY
				console.log('支付宝环境')
				this.getAuthCode()
				// #endif
				
			},
			touselist: function() {
				if (this.userInfo) {
					uni.navigateTo({
						url: '/pages/uselist/index'
					});
				}else {
					uni.showToast({
						title:'请先登录',
						icon: 'none'
					})
				}
				
			},
			obligation: function() {
				if (this.userInfo) {
					uni.showToast({
						title:'暂未开通,敬请期待',
						icon: 'none'
					})
					// uni.navigateTo({
					// 	url: '/pages/obligation/index'
					// });
				}else {
					uni.showToast({
						title:'请先登录',
						icon: 'none'
					})
				}
				// uni.navigateTo({
				// 	url: '/pages/obligation/index'
				// });
				
			},
			uselist() {
				if (this.userInfo) {
					uni.navigateTo({
						url: '/pages/uselist/index'
					});
				}else {
					uni.showToast({
						title:'请先登录',
						icon: 'none'
					})
				}
				
				
			},
			totext(e) {
				
				uni.navigateTo({
					url: '/pages/textare/index?cate=' + e
				});
			},
			tojoin: function() {
				uni.navigateTo({
					url: '/pages/joinus/index'
				});
			},

			handleChange({
				detail
			}) {
				console.log(detail);
			},
			toEquipment(){
				uni.navigateTo({
					url: '/pages/shop/equipmentList/index?shopId=' + this.shopId
				})
			}

		}
	};
</script>
<style>
	@import "./index.css";
</style>